package com.tanhua.server.service;

import com.tanhua.common.pojo.User;
import com.tanhua.common.utils.UserThreadLocal;
import com.tanhua.server.pojo.User;
import com.tanhua.server.pojo.UserInfo;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RecommendUserQueryParam;
import com.tanhua.server.vo.TodayBest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @program: my-tanhua
 * @description:
 * @author: xuejingjing
 * @create: 2021-09-21 12:45
 **/

@Service
public class TodayBestService {

    @Autowired
    private UserService userService;

    @Autowired
    private RecommendUserService recommendUserService;

    @Value("${tanhua.sso.default.user}")
    private  Long defaultUser;


    @Autowired
    private UserInfoService userInfoService;


    public TodayBest queryTodayBest() {
//       //校验token是否有效，通过sso的接口进行校验
//       User user = userService.queryUserByToken(token);
//       if(null == user){
//           //token非法或过期
//           return null;
//       }
        UserThreadLocal.get()


        //查询推荐用户-今日佳人

       TodayBest todayBest = recommendUserService.queryTodayBest(user.getId());
       if(null == todayBest){
           //给出默认的推荐用户
           TodayBest  todayBest = new TodayBest();
           todayBest.setId(defaultUser);
           todayBest.setFateValue(80L);//固定值
       }
       //补全个人信息
        UserInfo userInfo = userInfoService.queryUserInfoById(defaultUser);
       if(null ==userInfo){
           return null;
       }
        todayBest.setAvatar(userInfo.getLogo());
        todayBest.setNickname(userInfo.getNickName());
        todayBest.setTags(StringUtils.split(userInfo.getTags(),'，'));
        todayBest.setGender(userInfo.getSex().getValue() == 1 ? "man" : "woman");
        todayBest.setAge(userInfo.getAge());






    }

    public PageResult queryRecommendation(String token, RecommendUserQueryParam queryParam) {
        //验证token是否进有效，通过sso的接口进行校验
        User user = userService.queryUserByToken(token);
        if(null ==user){
            //token非法或者过期
            return null;
        }
        recommendUserService.queryCommendUserList(user.getId());

    }
}